<%@page import="dragon.core.system.po.SysUser"%>
<%@page import="dragon.core.util.GlobalParameter"%>
<%@page import="dragon.modules.system.user.dao.UserManagementRolesDao"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="dragon.core.system.po.SysUserGroup"%>
<%@page import="java.util.List"%>
<%@page import="dragon.modules.system.user.dao.UserGroupDaoImpl"%>
<%@ include file="../../../taglib.jsp"%>
<%
	int uid = Integer.parseInt(request.getParameter("uid").trim());
	int[] guids = new UserManagementRolesDao().getGroupIdByUserID(uid);
	List<SysUserGroup> ug = new UserGroupDaoImpl().loadAllUserGroup();
%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<base href="<%=basePath%>" />
<link rel="stylesheet" type="text/css" href="css/dialog.css" />
<%@ include file="/webmodules/console/css.jsp"%>
<%@ include file="/webmodules/console/js.jsp"%>
<script type="text/javascript">
function saveroles(){
	 var role =[];
	 $('input[name="roles"]:checked').each(function(){role.push($(this).val());});
	 var roles = role.join(",");
	$.post("dragon/modules/system/user/action/UserGroupHandler/addUserManagementRoles.ejw",{uid:${param.uid},roles:roles},function(data){
		if(data.result !=undefined && data.result == true){
			top.showMsg("", "保存成功！", false);
			top.closeWindow();
		}
		if(data.MESSAGE_ERROR != undefined && data.MESSAGE_ERROR != ''){
			top.showMsg("错误", data.MESSAGE_ERROR, true,'error');
		}else if(data.MESSAGE_WARNING != undefined && data.MESSAGE_WARNING != ''){
			top.showMsg("警告", data.MESSAGE_WARNING, true,'warning');
		}else if(data.MESSAGE_INFO != undefined && data.MESSAGE_INFO != ''){
			top.showMsg("", data.MESSAGE_INFO, false);
		}
	},'json');
}
</script>
</head>
<body>
	<div class="modartdiv" style="padding: 0px">
		<div id="divUI" style="overflow-y: auto; padding: 15px 60px 20px 20px; height: 200px;">
			<table style="width: 300px;">

				<%
					for (SysUserGroup sug : ug) {
						boolean f = false;
						if (guids != null) {
							for (int i : guids) {
								if (sug.getId() == i)
									f = true;
							}
						}
						out.print("<tr class=\"list_border_bg\">");
						out.print("<td class=\"table-cell-title\"><input type=\"checkbox\" name=\"roles\" value=\"" + sug.getId() + "\" " + (f ? "checked=\"checked\"" : "") + "/></td>");
						out.print("<td class=\"table-cell-input\">" + sug.getName() + "</td>");
						out.print("</tr>");
					}
				%>

			</table>
		</div>
		<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
			<tbody>
				<tr>
					<td>
						<div align="right">
							<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveroles();">确定</a> <a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cancel"
								onclick="top.closeWindow();">关闭</a>

						</div>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</body>
</html>